package vista.ejecucion;

import com.hackelare.coolgantt.CoolGanttFactory;
import com.hackelare.coolgantt.CoolGanttPhase;
import com.hackelare.coolgantt.CoolGanttTypeModel;
import com.hackelare.coolgantt.ICoolGantt;
import com.hackelare.coolgantt.ICoolGanttEvent;
import com.hackelare.coolgantt.demo.demoEvents;
import com.hackelare.coolgantt.legacy.model.ColorLabel;
import controlador.ejecucion.EjecucionUtils;
import controlador.ejecucion.GestorEjecucion;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import modelo.Ejecucion;
import modelo.Planificacion;
import modelo.TareaEjecucion;
import modelo.TareaPlanificacion;
import util.FechaUtil;
import util.HibernateUtil;
import util.SwingPanel;
import util.Tupla;
import vista.cotizacion.ExplorarSubObras;
import vista.ejecucion.lanzamiento.VentanaLanzamiento;
import vista.interfaces.ICallBack_v3;
import vista.planificacion.ArbolTareasGestor;
import vista.planificacion.EditarPlanificacion;
import vista.planificacion.PantallaEditarTarea;
import vista.planificacion.arbolTareas.ArbolIconoNodo;
import vista.planificacion.arbolTareas.ArbolIconoRenderer;

/**
 * Ventana Principal de Ejecucion !!
 * @author Iuga
 */
public class VentanaEjecucion extends javax.swing.JInternalFrame {

    private static final int OPTN_DATOS_GENERALES    = 0;
    private static final int OPTN_RRHH               = 1;
    private static final int OPTN_HERRAMIENTAS       = 2;
    private static final int OPTN_MATERIALES         = 3;
    private static final int OPTN_ALQUILERES_COMPRAS = 4;
    private static final int OPTN_ADICIONALES        = 5;
    private PanelDatosGeneralesDeTarea panelDatosTarea;
    private PanelHerramientas panelHerramientas;
    private PanelMateriales   panelMateriales;
    private PanelAlquileresCompras panelAlquileresCompras;
    private PanelRecursosHumanos panelRecursosHumanos;
    private PanelAdicionales panelAdicionales;
    private ICallBack_v3 panelSeleccionado;
    
    private ICoolGantt graph;
    private JComponent grafico;
    
    private GestorEjecucion gestor;
    
    ArbolTareasGestor arbolTareasGestor;
    private HashMap<Integer,PantallaEditarTarea> ventanasEditarTareasAbiertas;
    
    private ArbolIconoNodo nodoActualArbolTareas;
    private int idUltimoNodoArbolTareas=0;
    private TareaEjecucion tareaSeleccionada;
    private String nombreTipoRecursoEnPanel;
       
    /**
     * Ventana Principal de Ejecucion !!
     */
    public VentanaEjecucion(int idObra) {
        // Inicializo Ventana
        initComponents();
        // Inicializo el Gestor de a Ejecucion
        this.gestor = new GestorEjecucion(this,idObra);
         gestor.setIncluirSubtareas(cbIncluirSubtareas.isSelected());
        // Verifico si la obra esta en ejecucion
        checkSiObraTieneEjecución(idObra);
        // Segun el estado de la ejecucion, cambio el comportamiento
        cambiarSegunEstadoEjecucion();
        cargarComboTipoRecurso();      
        arbolTareasGestor=new ArbolTareasGestor(arbolTareas);
        inicializarArbolDeTareas();
        inicializarEventosArbol();
        inicializarGantt();
        initDetalleTareas();
        
    }
    
    private void cargarComboTipoRecurso()
    {
       Tupla tuplaDatos=new Tupla(OPTN_DATOS_GENERALES, "Datos generales");
       Tupla tuplaRRHH=new Tupla(OPTN_RRHH, "Recursos Humanos");
       Tupla tuplaHerramientas=new Tupla(OPTN_HERRAMIENTAS, "Herramientas");
       Tupla tuplaMateriales=new Tupla(OPTN_MATERIALES, "Materiales");
       Tupla tuplaAlquileresCompras=new Tupla(OPTN_ALQUILERES_COMPRAS, "Alquileres/Compras");
       Tupla tuplaAdicionales=new Tupla(OPTN_ADICIONALES, "Gastos Varios");
       DefaultTableModel modeloTablaMenu=(DefaultTableModel)tblRecursos.getModel();
       modeloTablaMenu.setRowCount(0);
       modeloTablaMenu.setColumnCount(0);
       Tupla[] valores=new Tupla[6];
       valores[0]=tuplaDatos;
       valores[1]=tuplaRRHH;
       valores[2]=tuplaHerramientas;
       valores[3]=tuplaMateriales;
       valores[4]=tuplaAlquileresCompras;
       valores[5]=tuplaAdicionales;
       modeloTablaMenu.addColumn("Menu", valores);
       
       
       tblRecursos.setModel(modeloTablaMenu);
       
       mostrarPanelCargaDeDatos(tuplaDatos);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnEmitirInformes = new javax.swing.JButton();
        btnCerrar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        arbolTareas = new javax.swing.JTree();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblRecursos = new javax.swing.JTable();
        panelCentral = new javax.swing.JPanel();
        cbIncluirSubtareas = new javax.swing.JCheckBox();
        panelGantt = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        lblNuevaTitulo = new javax.swing.JLabel();
        lblNuevaValor = new javax.swing.JLabel();
        lblEnProgresoTitulo = new javax.swing.JLabel();
        lblEnProgresoValor = new javax.swing.JLabel();
        lblCompletaTitulo = new javax.swing.JLabel();
        lblCompletaValor = new javax.swing.JLabel();
        lblCanceladaTitulo = new javax.swing.JLabel();
        lblCanceladaValor = new javax.swing.JLabel();
        lblEnEsperaTitulo = new javax.swing.JLabel();
        lblEnEsperaValor = new javax.swing.JLabel();
        lblImpedimentoTitulo = new javax.swing.JLabel();
        lblImpedimentoValor = new javax.swing.JLabel();
        btnDetalles = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        pbAvance = new javax.swing.JProgressBar();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        txtFechaFin = new com.toedter.calendar.JDateChooser();
        txtFechaInicio = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtEstado = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        lblObraNombre = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblObraLugar = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        lblObraPlanta = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lblObraFechaInicio = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        lblObraFechaFin = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        txtNroCotizacion = new javax.swing.JTextField();
        btnAbrirCotizacion = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        lblCotMontoTotal = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        btnAbrirPlanificacion = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        lblPlanificacionMontoTotal = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        lblFechaInicioPlanificacion = new javax.swing.JLabel();
        lblFechaFinPlanificacion = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taDescripcionEjecucion = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        btnFinalizarObra = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        btnLanzamiento = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Editar Ejecución");

        btnEmitirInformes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/List.png"))); // NOI18N
        btnEmitirInformes.setText("Emitir Informes");
        btnEmitirInformes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmitirInformesActionPerformed(evt);
            }
        });

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/block.png"))); // NOI18N
        btnCerrar.setText("Cancelar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/save_upload.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });
        jTabbedPane1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTabbedPane1FocusGained(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        arbolTareas.setModel(null);
        arbolTareas.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane5.setViewportView(arbolTareas);

        tblRecursos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblRecursos.setIntercellSpacing(new java.awt.Dimension(10, 5));
        tblRecursos.setMaximumSize(new java.awt.Dimension(300, 300));
        tblRecursos.setRowHeight(25);
        tblRecursos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblRecursos.setTableHeader(null);
        tblRecursos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblRecursosMousePressed(evt);
            }
        });
        jScrollPane2.setViewportView(tblRecursos);

        panelCentral.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalles"));
        panelCentral.setLayout(new java.awt.BorderLayout());

        cbIncluirSubtareas.setSelected(true);
        cbIncluirSubtareas.setText("IncluirSubtareas");
        cbIncluirSubtareas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbIncluirSubtareasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(cbIncluirSubtareas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCentral, javax.swing.GroupLayout.DEFAULT_SIZE, 713, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbIncluirSubtareas)
                .addContainerGap())
            .addComponent(panelCentral, javax.swing.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Gestion de Tareas", jPanel5);

        panelGantt.setLayout(new java.awt.BorderLayout());

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tareas por estado:"));

        lblNuevaTitulo.setText("Nuevas:");

        lblNuevaValor.setText("0");

        lblEnProgresoTitulo.setText("En Progreso:");

        lblEnProgresoValor.setText("0");

        lblCompletaTitulo.setText("Completa:");

        lblCompletaValor.setText("0");

        lblCanceladaTitulo.setText("Cancelada:");

        lblCanceladaValor.setText("0");

        lblEnEsperaTitulo.setText("En Espera:");

        lblEnEsperaValor.setText("0");

        lblImpedimentoTitulo.setText("Con Impedimento:");

        lblImpedimentoValor.setText("0");

        btnDetalles.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/chart.png"))); // NOI18N
        btnDetalles.setText("Detalles");
        btnDetalles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetallesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblNuevaTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblNuevaValor)
                .addGap(18, 18, 18)
                .addComponent(lblEnProgresoTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblEnProgresoValor)
                .addGap(18, 18, 18)
                .addComponent(lblCompletaTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCompletaValor)
                .addGap(18, 18, 18)
                .addComponent(lblCanceladaTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCanceladaValor)
                .addGap(18, 18, 18)
                .addComponent(lblEnEsperaTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblEnEsperaValor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblImpedimentoTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblImpedimentoValor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 373, Short.MAX_VALUE)
                .addComponent(btnDetalles)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(lblNuevaTitulo)
                .addComponent(lblNuevaValor)
                .addComponent(lblEnProgresoTitulo)
                .addComponent(lblEnProgresoValor)
                .addComponent(lblCompletaTitulo)
                .addComponent(lblCompletaValor)
                .addComponent(lblCanceladaTitulo)
                .addComponent(lblCanceladaValor)
                .addComponent(lblEnEsperaTitulo)
                .addComponent(lblEnEsperaValor)
                .addComponent(lblImpedimentoTitulo)
                .addComponent(lblImpedimentoValor)
                .addComponent(btnDetalles))
        );

        panelGantt.add(jPanel4, java.awt.BorderLayout.SOUTH);

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder("Avance de la Obra:"));

        pbAvance.setToolTipText("<HTML><b><u>Avance de la Obra:</u></b><br/>\nMuestra el progreso de la obra calculado con el estado de las tareas.<br>\n<b>Agregan Avance:</b><br>\nTareas en estado <b>Cancelada</b> o <b>Completa</b><br>\n<b>No modifican:</b><br>\nTareas en estado <b>En Progreso</b>,<b>En Espera</b>,<b>Impedimento</b> o <b>Nuevas</b><br>");
        pbAvance.setStringPainted(true);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(pbAvance, javax.swing.GroupLayout.DEFAULT_SIZE, 973, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pbAvance, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        panelGantt.add(jPanel11, java.awt.BorderLayout.NORTH);

        jTabbedPane1.addTab("Línea de Tiempo", panelGantt);

        jPanel2.setToolTipText("Datos Generales");

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la Ejecucion"));

        txtFechaFin.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtFechaFinFocusLost(evt);
            }
        });

        txtFechaInicio.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtFechaInicioFocusLost(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Fecha de Inicio: ");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Fecha de Fin: ");

        txtEstado.setEnabled(false);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Estado: ");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtFechaInicio, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
                    .addComponent(txtFechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtEstado))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Pedido de Obra"));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Nombre:");

        lblObraNombre.setText("---");
        lblObraNombre.setPreferredSize(new java.awt.Dimension(1, 1));
        lblObraNombre.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Planta: ");

        lblObraLugar.setText("---");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Lugar de la Planta:");

        lblObraPlanta.setText("---");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Fecha de Inicio:");

        lblObraFechaInicio.setText("---");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Fecha de Fin:");

        lblObraFechaFin.setText("---");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(10, 10, 10)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblObraFechaInicio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblObraFechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblObraNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblObraPlanta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblObraLugar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                    .addComponent(lblObraNombre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(lblObraPlanta))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(lblObraLugar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(lblObraFechaInicio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(lblObraFechaFin))
                .addContainerGap())
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la Cotización"));

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setText("Cotización sobre la que se planifico: ");

        txtNroCotizacion.setEditable(false);
        txtNroCotizacion.setHorizontalAlignment(javax.swing.JTextField.TRAILING);

        btnAbrirCotizacion.setText("Abrir Cotización");
        btnAbrirCotizacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAbrirCotizacionActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel15.setText("Monto Total Cotizado: ");

        lblCotMontoTotal.setText("---");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(txtNroCotizacion, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAbrirCotizacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(lblCotMontoTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtNroCotizacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAbrirCotizacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(lblCotMontoTotal))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de la Planificación"));

        btnAbrirPlanificacion.setText("Abrir Planificación");
        btnAbrirPlanificacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAbrirPlanificacionActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel19.setText("Monto Total Planificado: ");

        lblPlanificacionMontoTotal.setText("---");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Fecha de Inicio: ");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Fecha de Fin: ");

        lblFechaInicioPlanificacion.setText("---");

        lblFechaFinPlanificacion.setText("---");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(77, 77, 77)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGap(316, 316, 316)
                        .addComponent(btnAbrirPlanificacion, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 24, Short.MAX_VALUE))
                    .addComponent(lblPlanificacionMontoTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblFechaInicioPlanificacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblFechaFinPlanificacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(btnAbrirPlanificacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(lblPlanificacionMontoTotal))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFechaInicioPlanificacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFechaFinPlanificacion)))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(111, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Datos Generales", jPanel2);

        jPanel3.setToolTipText("Observaciones");

        taDescripcionEjecucion.setColumns(20);
        taDescripcionEjecucion.setRows(5);
        taDescripcionEjecucion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                taDescripcionEjecucionFocusLost(evt);
            }
        });
        jScrollPane1.setViewportView(taDescripcionEjecucion);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("A continuación escriba todas la observaciones que crea necesarias:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 981, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Observaciones", jPanel3);

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder("Acciones con la Ejecución"));

        btnFinalizarObra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/Stop.png"))); // NOI18N
        btnFinalizarObra.setText("<HTML>Dar por <b>Finalizada</b> la Obra");
        btnFinalizarObra.setActionCommand("Comenzar una planificación desde este presupuesto");
        btnFinalizarObra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFinalizarObraActionPerformed(evt);
            }
        });

        jLabel17.setText("<HTML>Dar por <b>Concluida o Finalizada</b> la ejecución de esta obra:");

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnFinalizarObra)
                    .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 943, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnFinalizarObra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(523, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Opciones de la Ejecución", jPanel1);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setText("Ejecución:");

        jLabel2.setText("<HTML>El objetivo de éste módulo es dar un seguimiento general de la obra, de los recursos y maquinarias que se utilizaron y los que se están utilizando. Para complementar, permite actualizar el avances de las tareas, dando a cualquier usuario un informe actualizado del estado actual de la obra. ");

        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/workflow/Workflow-Ejecucion.png"))); // NOI18N

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 975, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 981, Short.MAX_VALUE)
                    .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel16)
                .addContainerGap(368, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("<HTML><span color='002EB8'><b>Ayuda?</b></span>", jPanel9);

        btnLanzamiento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/iconos/var/16x16/accept_page.png"))); // NOI18N
        btnLanzamiento.setText("Lanzamiento");
        btnLanzamiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLanzamientoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnEmitirInformes)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnLanzamiento)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCerrar)
                .addContainerGap())
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnEmitirInformes)
                    .addComponent(btnCerrar)
                    .addComponent(btnGuardar)
                    .addComponent(btnLanzamiento))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        // llamo al comportamiento Cancelar de la ventana 
        cancelar();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // Llamo al guardar
        guardar();
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnLanzamientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLanzamientoActionPerformed
        VentanaLanzamiento win = new VentanaLanzamiento(gestor.getIdObraActual());
        SwingPanel.getInstance().addWindow(win);
        win.setVisible(true);
    }//GEN-LAST:event_btnLanzamientoActionPerformed

    private void jTabbedPane1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTabbedPane1FocusGained

    }//GEN-LAST:event_jTabbedPane1FocusGained

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
        System.out.println("Gano foco");
        JTabbedPane pan = (JTabbedPane)evt.getSource();
        switch(pan.getSelectedIndex())
        {
            case 0:
            // Ojo, vuelvo el foco al panel principal
            // Selecciono "Datos generales"
            if(tblRecursos.getRowCount()>0){
                tblRecursos.setRowSelectionInterval(0, 0);
            }
            refreshGanttAndData();
            break;
            case 1:
            // Actualizo el Gantt
            System.out.println("[DEBUG] Foco en el Gantt");
            refreshGanttAndData();
            refreshDetalleTareaDatos();
            refreshAvanceDeLaObra();
            break;
        }
    }//GEN-LAST:event_jTabbedPane1StateChanged

    private void taDescripcionEjecucionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_taDescripcionEjecucionFocusLost
        gestor.actualizarDescripcionEjecucion(taDescripcionEjecucion.getText());
    }//GEN-LAST:event_taDescripcionEjecucionFocusLost

    private void btnAbrirPlanificacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAbrirPlanificacionActionPerformed
        EditarPlanificacion eso = new EditarPlanificacion(gestor.getIdObraActual());
        SwingPanel.getInstance().addWindow(eso);
        eso.setVisible(true);
    }//GEN-LAST:event_btnAbrirPlanificacionActionPerformed

    private void btnAbrirCotizacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAbrirCotizacionActionPerformed

        ExplorarSubObras eso = new ExplorarSubObras(gestor.getIdCotizacionPlanificada());
        SwingPanel.getInstance().addWindow(eso);
        eso.setVisible(true);
    }//GEN-LAST:event_btnAbrirCotizacionActionPerformed

    private void txtFechaInicioFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtFechaInicioFocusLost

    }//GEN-LAST:event_txtFechaInicioFocusLost

    private void txtFechaFinFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtFechaFinFocusLost

    }//GEN-LAST:event_txtFechaFinFocusLost

    private void tblRecursosMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblRecursosMousePressed
        mostrarPanelCargaDeDatos(((Tupla)tblRecursos.getModel().getValueAt(tblRecursos.getSelectedRow(), 0)));
    }//GEN-LAST:event_tblRecursosMousePressed

    private void btnFinalizarObraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalizarObraActionPerformed

        // Tengo que guardar antes de continuar ... Pregunto
        String msgSave = "<HTML>"
        + "Antes de finalizar la <b>Ejecución</b> de ésta obra, necesita guardar los<br>"
        + "cambios sobre ésta ejecución."
        + "¿Desea Guardar los cambios y Continuar?";
        int seleccionSave = JOptionPane.showOptionDialog(
            this, // Componente padre
            msgSave, //Mensaje
            "Atención!!", // Título
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,    // null para icono por defecto.
            new Object[] { "Guardar y Continuar", "Cancelar"},// null para YES, NO y CANCEL
            "Cancelar");

        if (seleccionSave != -1)
        {
            if ((seleccionSave + 1) == 1) {
                // PRESIONO SI
                gestor.guardar();
            }
            else{
                return;
            }
        }
        
        // Veo si cerro/finalizo todas las tareas.
        int cantidadTareasNoCerradas = gestor.getCantidadDeTareasNoCerradas();
        if(cantidadTareasNoCerradas>0){
            String msgTareas = "<HTML><b>Estado de las Tareas:</b><br>Para poder finalizar la obra todas las tareas deben estár </b>concluidas</b><br>"
                    + " - Si su tarea esta completa, cambiela al estado <b>"+TareaEjecucion.ESTADO_COMPLETA+"</b><br>"
                    + " - En cambio, si la tarea no es requerida, cambiela al estado <b>"+TareaEjecucion.ESTADO_CANCELADA+"</b><br>"
                    + "<br><b>Cantidad de tareas no concluidas: </b>"+cantidadTareasNoCerradas+"<br>";
            mostrarMensaje(JOptionPane.ERROR_MESSAGE,"Atencion!",msgTareas);
            return;
        }
        
        // Aviso los posibles cambios irreversibles que se darán...
        String msg = "<HTML>"
        + "Está por <b>Finalizar</b> ésta obra. "
        + "Una vez que lo haga<br> la <b><i>Ejecución</i></b> concluirá y <b><span color='#FF0000'>no podrá modificarla</span></b>.<br>"
        + "¿Está seguro de concluir la planificación y comenzar la ejecución?";
        int seleccion = JOptionPane.showOptionDialog(
            this, // Componente padre
            msg, //Mensaje
            "Atención!!", // Título
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,    // null para icono por defecto.
            new Object[] { "Si, Finalizar la Ejecución de la Obra", "Cancelar"},// null para YES, NO y CANCEL
            "Cancelar");

        if (seleccion != -1)
        {
            if ((seleccion + 1) == 1) {
                // PRESIONO SI
                try
                {
                    gestor.finalizarEjecucion();
                    mostrarMensaje(JOptionPane.INFORMATION_MESSAGE,"Exito!","Se finalizó la obra correctamente!");
                    this.dispose();
                }
                catch(Exception e){
                    mostrarMensaje(JOptionPane.ERROR_MESSAGE,"Error!",e.getMessage());
                }
                
            }
        }

    }//GEN-LAST:event_btnFinalizarObraActionPerformed

    private void cbIncluirSubtareasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbIncluirSubtareasActionPerformed
        gestor.setIncluirSubtareas(cbIncluirSubtareas.isSelected());
        this.panelSeleccionado.actualizar(0, "", true,null);
    }//GEN-LAST:event_cbIncluirSubtareasActionPerformed

    private void btnEmitirInformesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmitirInformesActionPerformed
        EmitirInformes informesWin = new EmitirInformes(gestor.getPedidoDeObra(),gestor.getEjecucionActual());
       SwingPanel.getInstance().addWindow(informesWin);
       informesWin.setVisible(true);
    }//GEN-LAST:event_btnEmitirInformesActionPerformed

    private void btnDetallesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetallesActionPerformed
        GraficoCantidadDeTareasPorEstado gcte = new GraficoCantidadDeTareasPorEstado();
        
        final double[][] data = new double[1][6];
        
        data[0][0] = gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_NUEVA);
        data[0][1] = gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_ENPROGRESO);
        data[0][2] = gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_COMPLETA);
        data[0][3] = gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_CANCELADA);
        data[0][4] = gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_ENESPERA);
        data[0][5] = gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_IMPEDIMENTO);
        
        gcte.showGraph(data);
             
    }//GEN-LAST:event_btnDetallesActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTree arbolTareas;
    private javax.swing.JButton btnAbrirCotizacion;
    private javax.swing.JButton btnAbrirPlanificacion;
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnDetalles;
    private javax.swing.JButton btnEmitirInformes;
    private javax.swing.JButton btnFinalizarObra;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLanzamiento;
    private javax.swing.JCheckBox cbIncluirSubtareas;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblCanceladaTitulo;
    private javax.swing.JLabel lblCanceladaValor;
    private javax.swing.JLabel lblCompletaTitulo;
    private javax.swing.JLabel lblCompletaValor;
    private javax.swing.JLabel lblCotMontoTotal;
    private javax.swing.JLabel lblEnEsperaTitulo;
    private javax.swing.JLabel lblEnEsperaValor;
    private javax.swing.JLabel lblEnProgresoTitulo;
    private javax.swing.JLabel lblEnProgresoValor;
    private javax.swing.JLabel lblFechaFinPlanificacion;
    private javax.swing.JLabel lblFechaInicioPlanificacion;
    private javax.swing.JLabel lblImpedimentoTitulo;
    private javax.swing.JLabel lblImpedimentoValor;
    private javax.swing.JLabel lblNuevaTitulo;
    private javax.swing.JLabel lblNuevaValor;
    private javax.swing.JLabel lblObraFechaFin;
    private javax.swing.JLabel lblObraFechaInicio;
    private javax.swing.JLabel lblObraLugar;
    private javax.swing.JLabel lblObraNombre;
    private javax.swing.JLabel lblObraPlanta;
    private javax.swing.JLabel lblPlanificacionMontoTotal;
    private javax.swing.JPanel panelCentral;
    private javax.swing.JPanel panelGantt;
    private javax.swing.JProgressBar pbAvance;
    private javax.swing.JTextArea taDescripcionEjecucion;
    private javax.swing.JTable tblRecursos;
    private javax.swing.JTextField txtEstado;
    private com.toedter.calendar.JDateChooser txtFechaFin;
    private com.toedter.calendar.JDateChooser txtFechaInicio;
    private javax.swing.JTextField txtNroCotizacion;
    // End of variables declaration//GEN-END:variables

    
    public void setLblObraFechaFin(String lblObraFechaFin) {
        this.lblObraFechaFin.setText(lblObraFechaFin);
    }

    public void setLblObraFechaInicio(String lblObraFechaInicio) {
        this.lblObraFechaInicio.setText(lblObraFechaInicio);
    }

    public void setLblObraLugar(String lblObraLugar) {
        this.lblObraLugar.setText(lblObraLugar);
    }

    public void setLblObraNombre(String lblObraNombre) {
        this.lblObraNombre.setText(lblObraNombre);
    }

    public void setLblObraPlanta(String lblObraPlanta) {
        this.lblObraPlanta.setText(lblObraPlanta);
    }
    
    public void setTxtNroCotizacion(String nro) {
        this.txtNroCotizacion.setText(nro);
    }    
    
    public void setCotizacionMontoTotal(String monto) {
        this.lblCotMontoTotal.setText("$ "+monto);
    }     
       
    public void setFechaInicioEjecucion(Date fecha) {
        this.txtFechaInicio.setDate(fecha);
    }    
    
    public void setFechaFinEjecucion(Date fecha) {
        this.txtFechaFin.setDate(fecha);
    }
    
    public void setFechaInicioPlanificacion(Date fecha) {
        this.lblFechaInicioPlanificacion.setText(FechaUtil.getFecha(fecha));
    }    
    
    public void setFechaFinPlanificacion(Date fecha) {
        this.lblFechaFinPlanificacion.setText(FechaUtil.getFecha(fecha));
    }

    public void setDescripcionPlanificacion(String descripcion) {
        taDescripcionEjecucion.setText(descripcion);
    }

    public void setEstadoEjecucion(String estado){
        txtEstado.setText(estado);
    }
    
    public void setPlanificacionMontoTotal(String monto) {
        this.lblPlanificacionMontoTotal.setText("$ "+monto);
    }
    
    

    /**
     * Verifica si la obra tiene ejecucion,si no la tiene esta ventana
     * debería advertirlo y cerrarse.
     * @param idObra 
     */
    private void checkSiObraTieneEjecución(int idObra) {
        
    }
    
    /**
     * Segun el estado de la ejecucion, cambio el comportamiento.
     * Si está en alta, o en definicion, dejo todo editable
     * Si esta en baja o cancelada, no dejo editar nada.
     */
    private void cambiarSegunEstadoEjecucion() {
        
        if(gestor.getEstadoEjecucion().equals(Ejecucion.ESTADO_CREADA)){
            // CREADA
            enablearComponentes(true);
            
        }else{
            // CANCELADA y FINALIZADA
            enablearComponentes(false);
        }
        
    }
    
    /**
     * Cancela los cambios y cierra la ventana.
     * Antes pregunta si desea guardar los cambios.
     */
    private void cancelar() {

        if (gestor.esEjecucionEditable()) {
            int seleccion = JOptionPane.showOptionDialog(
                    this, // Componente padre
                    "<HTML>Si <b>cancela</b> todos los cambios realizados se <b><span color='#FF0000'>pederán</span></b> \n"
                    + "¿Desea guardar los cambios antes de cerrar?", //Mensaje
                    "Seleccione una opción", // Título
                    JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null, // null para icono por defecto.
                    new Object[]{"Guardar y Cerrar", "Cerrar", "Cancelar"}, // null para YES, NO y CANCEL
                    "Guardar y Cerrar");

            if (seleccion != -1) {
                switch (seleccion + 1) {
                    case 1:
                        // PRESIONO Guardar y Cerrar
                        System.out.println("Guardar y Cerrar:" + (seleccion + 1));
                        if (guardar()) {
                            this.dispose();
                        }
                        break;
                    case 2:
                        // PRESIONO Cerrar
                        System.out.println("Cerrar:" + (seleccion + 1));
                        this.dispose();
                        break;
                    case 3:
                    default:
                        System.out.println("Cancelar:" + (seleccion + 1));
                        // Cancelar - Nadaremos
                        break;
                }
            }
        }else{
            this.dispose();
        }
    }
    
    /**
     * Metodo a llamar cuando se quieren guardar los cambios !!
     * @return 
     */
    private boolean guardar() {
        
        int seleccion = JOptionPane.showOptionDialog(
            this, // Componente padre
            "<HTML>¿Desea <b>guardar</b> los cambios realizados sobre la Ejecución?", //Mensaje
            "Atencion!", // Título
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,    // null para icono por defecto.
            new Object[] { "Guardar", "Cancelar"},    // null para YES, NO y CANCEL
            "Guardar");

        if (seleccion != -1)
        {
           if((seleccion + 1)==1)
           {
              // Guardo los cambios !!
              if(gestor.guardar()){
                  // Guardado exitoso
                  mostrarMensaje(JOptionPane.INFORMATION_MESSAGE,"Exito!","<HTML>Se guardaron con <b>éxito</b> los cambios sobre la ejecución");
              }else{
                  // Guardado Fallido
                  mostrarMensaje(JOptionPane.INFORMATION_MESSAGE,"Error!","<HTML>Se produjo un <b>error</b> al guardar los cambios\nInténtelo nuevamente");
              }
           }
        }
        return true;
    }    
    
    
    private void mostrarPanelCargaDeDatos(Tupla tipoRecurso)
    {
        int idTipoRecurso=tipoRecurso.getId();
        JPanel contenido=null;
        arbolTareas.setVisible(true);
        cbIncluirSubtareas.setVisible(true);
        switch(idTipoRecurso)
        {
            case OPTN_DATOS_GENERALES:
                if(this.panelDatosTarea==null){
                    this.panelDatosTarea =  new PanelDatosGeneralesDeTarea(this.gestor);
                }
                panelSeleccionado=this.panelDatosTarea;
                this.panelDatosTarea.actualizar();
                contenido=panelDatosTarea;
                cbIncluirSubtareas.setEnabled(false);
                break;
            
            case OPTN_RRHH:
                if(this.panelRecursosHumanos==null){
                    this.panelRecursosHumanos =  new PanelRecursosHumanos(this.gestor);
                }
                panelSeleccionado=this.panelRecursosHumanos;
                this.panelRecursosHumanos.actualizar();
                contenido=panelRecursosHumanos;
                break;
            case OPTN_HERRAMIENTAS:
                if(this.panelHerramientas==null){
                    this.panelHerramientas =  new PanelHerramientas(this.gestor);
                }
                panelSeleccionado=this.panelHerramientas;
                this.panelHerramientas.actualizar();
                contenido=panelHerramientas;
                break;                
            case OPTN_MATERIALES:
                if(this.panelMateriales==null){
                    this.panelMateriales =  new PanelMateriales(this.gestor);
                }
                panelSeleccionado=this.panelMateriales;
                this.panelMateriales.actualizar();
                contenido=panelMateriales;
                break;
            case OPTN_ALQUILERES_COMPRAS:
                if(this.panelAlquileresCompras==null){
                    this.panelAlquileresCompras =  new PanelAlquileresCompras(this.gestor);
                }
                panelSeleccionado=this.panelAlquileresCompras;
                this.panelAlquileresCompras.actualizar();
                contenido=panelAlquileresCompras;
                break;
            case OPTN_ADICIONALES:
                if(this.panelAdicionales==null){
                    this.panelAdicionales =  new PanelAdicionales(this.gestor);
                }
                panelSeleccionado=this.panelAdicionales;
                cbIncluirSubtareas.setEnabled(false);
                this.panelAdicionales.actualizar(); 
                contenido=panelAdicionales;
                arbolTareas.setVisible(false);                
                break;
        }
        
        /*if(idTipoRecurso==OPTN_ADICIONALES){
            arbolTareas.setVisible(false);
            cbIncluirSubtareas.setVisible(false);
        }
        else {
            arbolTareas.setVisible(true);
            cbIncluirSubtareas.setVisible(true);
        }*/
        
        nombreTipoRecursoEnPanel=tipoRecurso.toString();
        setearPanelCentral(contenido);
        
        
    }
    protected void setearPanelCentral(JPanel panel){
        setearNombrePanelCentral();
         panelCentral.removeAll();
        // panelCentral.setViewportView(panel);
         panelCentral.add(panel, BorderLayout.CENTER);
         panel.setVisible(true);  
         this.updateUI();
    }  
    
    private void setearNombrePanelCentral()
    {
        String nombreCompletoPanel=nombreTipoRecursoEnPanel.toString();
        if(tareaSeleccionada!=null){
        nombreCompletoPanel=nombreCompletoPanel + " - Tarea "+tareaSeleccionada.getNombre();
        }
         panelCentral.setBorder(javax.swing.BorderFactory.createTitledBorder(nombreCompletoPanel));
    }
    
    private void inicializarArbolDeTareas()
    {
        DefaultTreeModel modelo=gestor.cargarModeloArbolTareas();
        arbolTareas.setModel(modelo);
        arbolTareas.setCellRenderer(new ArbolIconoRenderer());
        //inicializarEventosArbol();
        arbolTareas.repaint();  
        
        if(idUltimoNodoArbolTareas!=0)
        {
            ArbolIconoNodo ultimoNodoArbolTareas=arbolTareasGestor.getNodoArbolTareasPorId(arbolTareas,idUltimoNodoArbolTareas);
            /*if( ArbolDeTareasTipos.esGruposRecursos(tipoUltimoNodoArbolTareas))
            {
              ultimoNodoArbolTareas=arbolTareasGestor.obtenerNodoGrupoDeTarea( ultimoNodoArbolTareas, tipoUltimoNodoArbolTareas);  
            }*/
            TreePath tpt=new TreePath(ultimoNodoArbolTareas.getPath());
            arbolTareas.expandPath(tpt);
            idUltimoNodoArbolTareas=0;
        }
    }
    
    private void inicializarEventosArbol()
    {
       //Listener del arbol
        arbolTareas.addMouseListener(new MouseAdapter() {
                
            private void clickEnArbol(MouseEvent mouseEvent) {
              TreePath tp = arbolTareas.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
                if(tp==null)
                   {
                     mouseEvent.consume();
                     idUltimoNodoArbolTareas=0;
                     return;
                   }
                final ArbolIconoNodo nodo  = ArbolTareasGestor.getNodoDeTreeNodePath(tp);
                if(nodo==null)
                { 
                    idUltimoNodoArbolTareas=0;
                    return;
                }
                
                idUltimoNodoArbolTareas=nodo.getId();
                
                  
            
                setearTareaEjecucionSeleccionada(idUltimoNodoArbolTareas );
                mouseEvent.consume();
            }
 
            @Override
        public void mousePressed(MouseEvent e)  { clickEnArbol(e); }
            @Override
        public void mouseReleased(MouseEvent e) {/* clickEnArbol(e);*/ }
            @Override
        public void mouseClicked(MouseEvent e)  { /*clickEnArbol(e);*/ }
            });
        
        
    }
    
    private TareaEjecucion setearTareaEjecucionSeleccionada(int hash)    {
       tareaSeleccionada= gestor.setearTareaEjecucionSeleccionada(hash);
        actualizarPaneles();
        
        return tareaSeleccionada;
    }
    
    
    
    /**
     * Muestra un mensaje
     * @param tipo
     * @param titulo
     * @param mensaje 
     */
    public void mostrarMensaje(int tipo,String titulo,String mensaje)
    {
         JOptionPane.showMessageDialog(this.getParent(),mensaje,titulo,tipo);
    } 
    
    public void actualizarPaneles(){
    
        setearNombrePanelCentral();
        if(this.panelDatosTarea!=null)
        {this.panelDatosTarea.actualizar();}
        if(this.panelRecursosHumanos!=null)
        {this.panelRecursosHumanos.actualizar();}
        if(this.panelHerramientas!=null)
        {this.panelHerramientas.actualizar();}
        if(this.panelMateriales!=null)
        {this.panelMateriales.actualizar();}
        if(this.panelAlquileresCompras!=null)
        {this.panelAlquileresCompras.actualizar();}
        if(this.panelAdicionales!=null)
        {this.panelAdicionales.actualizar();}
        
    }

    private void inicializarGantt() {
        graph = CoolGanttFactory.create();
        graph.setEventHandler(new demoEvents());

        initTypeModel();
        initModel();

        grafico = graph.getComponent();
               
        panelGantt.add(grafico, BorderLayout.CENTER);
        pack();
        setVisible(true);
        
        // Agrego el menu del boton derecho
        //grafico.setComponentPopupMenu(jpm);
        
        // Le doy el zoom que quiero
         graph.setZoomOut();
          graph.setZoomOut();
           graph.setZoomOut();
            graph.setZoomOut();
             graph.setZoomOut();
         
        graph.setEventHandler(new GanttEventMouse());
    }
       
    /**
     * Inicializa los tipos de tarea
     */
    private void initTypeModel() {
        CoolGanttTypeModel typeModel = new CoolGanttTypeModel();
        typeModel.addType(TareaEjecucion.ESTADO_CANCELADA, new ColorLabel("", TareaEjecucion.ESTADO_COLORFONDO_CANCELADA, 0));
        typeModel.addType(TareaEjecucion.ESTADO_COMPLETA, new ColorLabel("", TareaEjecucion.ESTADO_COLORFONDO_COMPLETA, 0));
        typeModel.addType(TareaEjecucion.ESTADO_ENESPERA, new ColorLabel("", TareaEjecucion.ESTADO_COLORFONDO_ENESPERA, 0));
        typeModel.addType(TareaEjecucion.ESTADO_ENPROGRESO, new ColorLabel("", TareaEjecucion.ESTADO_COLORFONDO_ENPROGRESO, 0));
        typeModel.addType(TareaEjecucion.ESTADO_IMPEDIMENTO, new ColorLabel("", TareaEjecucion.ESTADO_COLORFONDO_IMPEDIMENTO, 0));
        typeModel.addType(TareaEjecucion.ESTADO_NUEVA, new ColorLabel("", TareaEjecucion.ESTADO_COLORFONDO_NUEVA, 0));
        graph.getModel().setTypeModel(typeModel);
    }

    private void initModel() {
        int n = 0;
        // TODO: Llenar el Gantt
        List<TareaPlanificacion> lista = gestor.getTareasPadres();
        for (int i = 0; i < lista.size(); i++) {
            TareaEjecucion tplan = (TareaEjecucion) lista.get(i);
            cargarTareasRecursivas(tplan, n);
        }
        graph.refreshModel();
    }

    private void cargarTareasRecursivas(TareaEjecucion tplan, int n) {

        CoolGanttPhase p1 = new CoolGanttPhase();

        // Si no se puede modificar las bloqueo...
        if (gestor.esEjecucionEditable()) {
            p1.setEditable(true);
        } else {
            p1.setEditable(false);
        }

//        // WORKARROUND DE HORAS DE TAREAS
//        Calendar fInicio = Calendar.getInstance();
//        fInicio.setTime(tplan.getFechaInicio());
//        fInicio.set(Calendar.HOUR,21);
//        fInicio.set(Calendar.MINUTE,0);
//        fInicio.set(Calendar.SECOND,0);
//        fInicio.set(Calendar.MILLISECOND,0);
//        
//        Calendar fFin = Calendar.getInstance();
//        fFin.setTime(tplan.getFechaFin());
//        fFin.set(Calendar.HOUR,21);
//        fFin.set(Calendar.MINUTE,0);
//        fFin.set(Calendar.SECOND,0);
//        fFin.set(Calendar.MILLISECOND,0);        
        
        
        p1.setId(tplan.hashCode());
        p1.setNombre(tplan.getNombre());
        p1.setType(tplan.getEstado());
        p1.setStartDate(tplan.getFechaInicio());
        p1.setEndDate(tplan.getFechaFin());

        // Agrego el nivel de tarea al gantt
        for (int j = 0; j < n; j++) {
            p1.setNombre(p1.getNombre() + " @");
        }

        graph.addPhase(p1);

        if (tplan.getSubtareas() != null) {
            for (int i = 0; i < tplan.getSubtareas().size(); i++) {
                TareaEjecucion tp = (TareaEjecucion)tplan.getSubtareas().get(i);
                int nuevoNivel = n + 1;
                cargarTareasRecursivas(tp, nuevoNivel);
            }
        }
    }
    
    public void refreshGanttAndData()
    {
        if(graph!=null){
            // Limpio las tareas anteriores
            graph.getModel().getPhaseList().clear();
            graph.refreshModel();

            // Cargo de nuevo todas las tareas
            int n = 0;
            // TODO: Llenar el Gantt
            List<TareaPlanificacion> lista = gestor.getTareasPadres();
            for (int i = 0; i < lista.size(); i++) {
                TareaEjecucion tplan = (TareaEjecucion)lista.get(i);
                cargarTareasRecursivas(tplan,n);
            }

            // refresco el modelo
            graph.refreshModel();
            updateGantt();
        }
    }    
    
    private void updateGantt()
    {
        panelGantt.remove(grafico);
        pack();
        grafico = graph.getComponent();
        panelGantt.add(grafico, BorderLayout.CENTER);
        pack();
    }    

    private void enablearComponentes(boolean anulo) {
        btnFinalizarObra.setEnabled(anulo);
        btnGuardar.setEnabled(anulo);
        if(anulo){
            btnCerrar.setText("Cerrar");
        }else{
            btnCerrar.setText("Cancelar");
        }
        txtFechaInicio.setEnabled(anulo);
        txtFechaFin.setEnabled(anulo);
        taDescripcionEjecucion.setEnabled(anulo);
    }

    private void initDetalleTareas() {
        lblNuevaTitulo.setForeground(TareaEjecucion.ESTADO_COLOR_NUEVA);
        lblEnProgresoTitulo.setForeground(TareaEjecucion.ESTADO_COLOR_ENPROGRESO);
        lblCompletaTitulo.setForeground(TareaEjecucion.ESTADO_COLOR_COMPLETA);
        lblCanceladaTitulo.setForeground(TareaEjecucion.ESTADO_COLOR_CANCELADA);
        lblEnEsperaTitulo.setForeground(TareaEjecucion.ESTADO_COLOR_ENESPERA);
        lblImpedimentoTitulo.setForeground(TareaEjecucion.ESTADO_COLOR_IMPEDIMENTO);
        
        refreshDetalleTareaDatos();
        refreshAvanceDeLaObra();
        
    }

    private void refreshDetalleTareaDatos() {
        lblNuevaValor.setText(""+gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_NUEVA));
        lblEnProgresoValor.setText(""+gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_ENPROGRESO));
        lblCompletaValor.setText(""+gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_COMPLETA));
        lblCanceladaValor.setText(""+gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_CANCELADA));
        lblEnEsperaValor.setText(""+gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_ENESPERA));
        lblImpedimentoValor.setText(""+gestor.getCantidadTareasPorEstado(TareaEjecucion.ESTADO_IMPEDIMENTO));
    }
    
    private void refreshAvanceDeLaObra(){
        gestor.setAvanceDeLaObra(pbAvance);
    }
    
    public class GanttEventMouse implements ICoolGanttEvent {

        @Override
        public Date inGetProjectStartDate() {
            return gestor.getFechaInicioObra();
        }

        @Override
        public Date inGetProjectEndDate() {
            return gestor.getFechaFinObra();
        }

        @Override
        public void outClickPhase(int i) {
            // ue hacemos cuando se hace click en la tarea ??
        }

        @Override
        public void outMovePhase(int i, Date date) {
            gestor.setTareaGanttSeleccionada(i);
            gestor.tareaCambioFecha(date);
        }

        @Override
        public void outExtendPhaseBackward(int i, Date date) {
            gestor.setTareaGanttSeleccionada(i);
            try{
            gestor.actualizarFechaInicioTarea(date);
            }
            catch(Exception e){
               Logger.getLogger(VentanaEjecucion.class.getName()).log(Level.SEVERE, null, e); ;
            }
        }

        @Override
        public void outExtendPhaseForward(int i, Date date) {
            gestor.setTareaGanttSeleccionada(i);
            try{
            gestor.actualizarFechaFinTarea(date);
            }
            catch(Exception e){
               Logger.getLogger(VentanaEjecucion.class.getName()).log(Level.SEVERE, null, e); ;
            }
        }
    }
}
